package com.zz.controller;

import com.zz.entity.User;
import com.zz.repository.UserRepository;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.Random;

@Controller
public class URLController {
    @Resource
    UserRepository userRepository;
    @GetMapping("login")
    public String login(User user){
        User user1 = userRepository.findByNameAndPwd(user.getName(),user.getPwd());
        if (user1!=null){
            return "index.html";
        }
        return "login.html";
    }
    @GetMapping("save")
    private String save(@RequestParam("name") String name, @RequestParam("pwd") String pwd){
        User user = new User();
        Random random = new Random();
        user.setId(random.nextInt());
        user.setName(name);
        user.setPwd(pwd);
        userRepository.save(user);
        return "login.html";
    }

}
